﻿namespace Bowlus.Azure.ServiceManagementWrapper
{
    using System;
    using System.Globalization;
    using System.Net;
    using System.Runtime.Serialization;
    using System.Security.Cryptography.X509Certificates;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.ServiceModel.Web;
    using System.Text;
    using System.Xml;
    using Bowlus.Azure.ServiceManagementWrapper.Contracts;
    using System.Collections.Generic;

    public class ServiceManagementWrapper2 : Bowlus.Azure.ServiceManagementWrapper.IServiceManagementWrapper
    {

        public ServiceDeployment GetDeploymentBySlot(string serviceName, string deploymentSlot)
        {
            // deployment(89).Bowlus.Bowlus.AppHost_IN_0
            var _instanceId = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CurrentRoleInstance.Id;
            var _deploymentId = _instanceId.Substring(0, _instanceId.IndexOf('.'));

            var deployment = new ServiceDeployment();

            deployment.Configuration = "deploymentConfiguration";
            deployment.DeploymentSlot = _deploymentId;
            deployment.ExtensionData = null;
            deployment.Label = _deploymentId;
            deployment.Name = _deploymentId;
            deployment.PrivateId = _deploymentId;


            IList<RoleInstance> list = new List<RoleInstance>();
            RoleInstance instance = new RoleInstance();
            instance.RoleName = "Bowlus.AppHost";
            instance.InstanceName = _deploymentId + ".Bowlus.Bowlus.AppHost_IN_0";
            instance.InstanceStatus = "Ready";
            list.Add(instance);
            instance = new RoleInstance();
            instance.RoleName = "Bowlus.FrontEnd";
            instance.InstanceName = _deploymentId + ".Bowlus.Bowlus.FrontEnd_IN_0";
            instance.InstanceStatus = "Ready";
            list.Add(instance);
            deployment.RoleInstanceList = new RoleInstanceCollection(list);

            deployment.Status = "Ready";
            deployment.UpgradeDomainCount = 2;
            deployment.UpgradeStatus = null;
            deployment.Url = null; // new Uri("cloudsamurai.cloudapp.net");
            return deployment;
        }
    }
}